<template>
  <div class="home">
    <!-- 筛选 -->
    <div class="search_content">
      <van-nav-bar
        :title="$route.meta.title"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
      <van-search
        v-model="requestParams.codeNo"
        placeholder="请输入车架号或者车牌号或者任务名称"
        shape="round"
        @search="initData"
        @clear="clearSearch"
      />
      <div class="search_item">
        <van-dropdown-menu :close-on-click-outside="false">
          <van-dropdown-item
            title="任务状态"
            ref="statusRef"
          >
            <div class="searchbox">
              <div class="title">任务一级状态</div>
              <div class="insureList">
                <div
                  class="insure_item"
                  :class="item.check ? 'active' : ''"
                  v-for="(item, index) in oneBillStatusList"
                  :key="index"
                  @click="handleSearchSelect(index, 'oneBillStatusList')"
                >
                  {{ item.name }}
                </div>
              </div>
              <div class="title">任务二级状态</div>
              <div class="insureList">
                <div
                  class="insure_item"
                  :class="item.check ? 'active' : ''"
                  v-for="(item, index) in twoBillStatusList"
                  :key="index"
                  @click="handleSearchSelect(index, 'twoBillStatusList')"
                >
                  {{ item.name }}
                </div>
              </div>

              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleSelectReset('statusRef')"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('statusRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>

          <van-dropdown-item
            title="任务类型"
            ref="taskTypeRef"
          >
            <div class="searchbox">
              <div class="insureList">
                <div
                  class="insure_item"
                  :class="item.check ? 'active' : ''"
                  v-for="(item, index) in taskTypeList"
                  :key="index"
                  @click="handleSearchSelect(index, 'taskTypeList')"
                >
                  {{ item.name }}
                </div>
              </div>
              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleSelectReset('taskTypeRef')"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('taskTypeRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>

          <van-dropdown-item
            title="应跟进时间"
            ref="followRef"
          >
            <div class="searchbox">
              <div class="flex">
                <van-field
                  class="time_item"
                  v-model="requestParams.taskStartCreateTime"
                  label=""
                  :placeholder="'开始时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('taskStartCreateTime')"
                />
                <span class="time_icon">-</span>
                <van-field
                  class="time_item"
                  v-model="requestParams.taskEndCreateTime"
                  label=""
                  :placeholder="'结束时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('taskEndCreateTime')"
                />
              </div>

              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleSelectReset('followRef')"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('followRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>

          <van-dropdown-item
            title="筛选"
            ref="filterRef"
          >
            <div class="searchbox timebox">
              <van-field
                v-model="requestParams.fixCenterName"
                name="维修中心"
                label="维修中心"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('fixCenterId', 'fixCenterName')"
              />
              <van-field
                v-model="requestParams.taskPersonName"
                name="跟进人"
                label="跟进人"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('taskPersonId', 'taskPersonName')"
              />
              <van-field
                v-model="requestParams.serverPsnName"
                name="服务顾问"
                label="服务顾问"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('serverPsnId', 'serverPsnName')"
              />
              <van-field
                v-model="requestParams.taskResultName"
                name="是否到店"
                label="是否到店"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('taskResult', 'taskResultName')"
              />

              <van-field
                name="radio"
                label="是否默认跟进人"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isFollowPerson"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>
              <van-field
                name="radio"
                label="是否逾期任务"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isExceed"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>
              <van-field
                name="radio"
                label="是否生成预约单"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isGenRepBook"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>
              <van-field
                name="radio"
                label="是否厂家任务"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isFactTask"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>

              <van-field
                name="radio"
                label="是否会员客户"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isHuiYuan"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>
              <van-field
                name="radio"
                label="是否会员绑定车辆"
                input-align="right"
                label-width="170px"
              >
                <template #input>
                  <van-radio-group
                    v-model="requestParams.isHYCar"
                    direction="horizontal"
                  >
                    <van-radio
                      :name="item.value"
                      v-for="(item, index) in isflagList"
                      :key="index"
                    >
                      {{ item.name }}
                    </van-radio>
                  </van-radio-group>
                </template>
              </van-field>

              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleAccidentReset()"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('filterRef')"
                >
                  确认
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="saveBtn"
                  @click="saveSearch('filterRef')"
                >
                  保存方案
                </van-button>
              </div>
            </div>
          </van-dropdown-item>
        </van-dropdown-menu>

        <!-- 服务顾问下拉 -->
        <van-popup
          v-model="showSelectPicker"
          position="bottom"
        >
          <van-field
            name="模糊查询"
            input-align="left"
            v-model="likeWho"
            label="模糊查询"
            v-if="
              likeWhoField == 'fixCenterId' ||
              likeWhoField == 'taskPersonId' ||
              likeWhoField == 'serverPsnId'
            "
            placeholder="请输入模糊查询关键词"
          />
          <van-picker
            show-toolbar
            :columns="columns"
            @confirm="handleSelectConfirm"
            @cancel="showSelectPicker = false"
            value-key="name"
          />
        </van-popup>
        <!-- 时间选择 -->
        <van-popup
          v-model="showPickerDate"
          position="bottom"
        >
          <van-datetime-picker
            v-model="currentDate"
            type="date"
            @cancel="onCancelDate"
            @confirm="onConfirmDate"
            :formatter="formatter"
          />
        </van-popup>
      </div>
    </div>

    <!-- 列表 -->
    <van-pull-refresh
      v-model="refreshing"
      @refresh="onRefresh"
    >
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="loadData"
        v-if="recordList && recordList.length != 0"
      >
        <div class="orderList">
          <div
            class="orderbox"
            v-for="(item, index) in recordList"
            :key="index"
          >
            <div class="flex">
              <div
                class="taskCheck"
                v-if="showTransmitFlag"
              >
                <van-checkbox
                  v-model="item.check"
                  shape="square"
                  icon-size="15px"
                ></van-checkbox>
              </div>
              <div
                class="orderItem"
                @click="goDetail(item)"
              >
                <div class="orderItem_box">
                  <div class="orderItem_header">
                    <div class="orderItem_lt">
                      <div class="carNo">
                        {{ item.taskName }}
                        <span class="carStatus">{{ item.oneBillStatus }}</span>
                        <span
                          class="carStatus"
                          v-if="item.taskResult && item.taskResult != '暂无'"
                        >{{ item.taskResult }}</span>
                      </div>
                      <div class="vinNobox">
                        <div
                          class="vinNo"
                          v-if="item.vinCode"
                        >
                          {{ item.vinCode }}
                        </div>
                        <div class="orderItem_rt">
                          跟进人：{{ item.taskPerson ? item.taskPerson : "-" }}
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="orderItem_content">
                  <div class="orderItem_data">
                    <div class="order_label">车主</div>
                    <div class="txt">
                      {{ item.customerName ? item.customerName : "-" }}
                    </div>
                  </div>
                  <div class="orderItem_data">
                    <div class="order_label">跟进状态</div>
                    <div class="txt">
                      {{ item.twoBillStatus ? item.twoBillStatus : "-" }}
                    </div>
                  </div>

                  <div class="orderItem_data">
                    <div class="order_label">客户管家</div>
                    <div class="txt">
                      {{ item.cusButName ? item.cusButName : "-" }}
                    </div>
                  </div>
                  <div class="orderItem_data">
                    <div class="order_label">服务顾问</div>
                    <div class="txt">
                      {{ item.serverName ? item.serverName : "-" }}
                    </div>
                  </div>
                  <!-- <div class="orderItem_data">
                    <div class="order_label">车型</div>
                    <div class="txt">{{ item.carModel }}</div>
                  </div> -->
                  <!-- <div class="orderItem_data">
                    <div class="order_label">行驶里程数</div>
                    <div class="txt">{{ item.carMiles }}km</div>
                  </div> -->

                  <div class="orderItem_data time">
                    <div class="order_label">当店最后进场</div>
                    <div class="txt">{{ item.dateIn ? item.dateIn : "-" }}</div>
                  </div>
                  <div class="orderItem_data time">
                    <div class="order_label">应跟进时间</div>
                    <div class="txt">
                      {{ item.shuldFollowTime ? item.shuldFollowTime : "-" }}
                    </div>
                  </div>
                  <div class="orderItem_data time">
                    <div class="order_label">最近跟进时间</div>
                    <div class="txt">
                      {{ item.lastFollowInTime ? item.lastFollowInTime : "-" }}
                    </div>
                  </div>
                </div>
                <div class="orderItem_label">
                  <div
                    class="label_item"
                    v-for="(el, i) in item.label"
                    :key="i"
                  >
                    {{ el }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </van-list>
      <van-empty
        class="noContent"
        description="暂无数据"
        v-else
      />
    </van-pull-refresh>

    <div class="addBtn">
      <div
        class="footerBtn orderItem_filebox"
        @click="handleShowTransmit"
        v-if="!showTransmitFlag && recordList.length != 0"
      >
        任务转交
      </div>
      <div
        class="flex"
        v-if="showTransmitFlag && recordList.length != 0"
      >
        <div
          class="footerBtn comfirmBtn"
          @click.stop="handleTransmitSubmit"
        >
          确认转交
        </div>
        <div
          class="footerBtn cancelBtn"
          @click.stop="handleTransmitCancel"
        >
          取消
        </div>
      </div>
    </div>

    <van-dialog
      v-model="updateServiceVisible"
      title="转交跟进人"
      show-cancel-button
      @confirm="updateServiceConfirm"
      :before-close="beforeCloseUpdateTel"
    >
      <van-field
        v-model="updateServiceData.fixCenterName"
        name="所属维修中心"
        label="所属维修中心"
        input-align="right"
        placeholder="请选择"
        readonly
        right-icon="arrow"
        @click="
          handleUpdateSelect(
            'updateServiceData',
            'fixCenterId',
            'fixCenterName'
          )
        "
      />

      <van-field
        v-model="updateServiceData.followPersonName"
        name="跟进人"
        label="跟进人"
        input-align="right"
        placeholder="请选择"
        readonly
        right-icon="arrow"
        @click="
          handleUpdateSelect(
            'updateServiceData',
            'followPersonID',
            'followPersonName'
          )
        "
      />
    </van-dialog>

    <van-popup
      v-model="updateSelectVisible"
      position="bottom"
    >
      <van-picker
        show-toolbar
        :columns="updateColumns"
        @confirm="handleUpdateSelectConfirm"
        @cancel="updateSelectVisible = false"
        value-key="name"
      />
    </van-popup>

    <div
      class="loading"
      v-if="loading"
    >
      <van-loading
        size="30px"
        class="loadbox"
        color="#fff"
        text-color="#fff"
      >
        加载中...
      </van-loading>
      <div class="mask"></div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Search, DropdownMenu, DropdownItem, Empty, Dialog, Notify, Loading, Toast } from 'vant'
import taskApi from '@/api/taskApi'
import commonApi from '@/api/commonApi'
import { getCookies } from '@/utils/util.js'

export default {
  name: 'repairOrder',
  components: {
    Search,
    DropdownMenu,
    DropdownItem,
    Empty,
    Dialog,
    Notify,
    Loading,
    Toast,
  },
  data() {
    return {
      value: '',
      carCouponList: [
        { name: '是', code: 1, check: false },
        { name: '否', code: 0, check: false },
      ],
      taskTypeList: [],
      statusList: [
        { name: '已处理', code: 1, check: false },
        { name: '未处理', code: 2, check: false },
      ],

      recordList: [
        // {
        //   billId: "1", //单据ID
        //   carNo: "闽D66666", //车牌号
        //   taskName: "闽D66666定期保养招揽", //任务名称
        //   taskPerson: "张三", //跟进人
        //   oneBillStatus: "未处理", //任务一级状态
        //   twoBillStatus: "未处理", //任务二级状态
        //   customerName: "李四", //客户名称
        //   mobile1: "", //手机1
        //   mobile12: "", //手机2
        //   serverName: "王武", //所属服务顾问
        //   carModel: "CT5 2,0T", //车型
        //   carMiles: "8888", //公里数
        //   dateIn: "2023-06-25", //最近进场日期
        // },
      ],
      columns: [],
      showSelectPicker: false,
      requestParams: {
        codeNo: '', //车架号或者车牌号，String，必填
        pageNo: 1, //当前页数，默认从1开始，每页显示十条，int，不能为空或者小于1
        oneBillStatus: '', //任务一级状态
        twoBillStatus: '', //任务二级状态
        taskTypeId: '', //任务类型ID值
        taskPersonId: '', //任务跟进人，ID值
        taskPersonName: '', //任务跟进人，ID值
        fixCenterId: '',
        fixCenterName: '',
        serverPsnId: '',
        serverPsnName: '',
        taskStartCreateTime: '',
        taskEndCreateTime: '',
        isExceed: '', //是否逾期，1为是，0为否
        isGenRepBook: '', //是否生成维修预约单
        billId: '', //本身单据ID，此为详细界面使用
        carId: '', //车辆ID，此为详细界面使用
        userId: getCookies('userId'), //用户ID，必填，String
        isFactTask: '', //是否厂家任务
        isHuiYuan: '', //是否会员客户
        isHYCar: '', //是否会员绑定车辆
        isFollowPerson: 1,
        taskResult: '',
        taskResultName: '',
      },
      carCouponIndex: null,

      repairCenterList: [
        { name: '厦门路虎', code: 1 },
        { name: '厦门捷豹', code: 2 },
      ],
      serviceList: [
        // { name: '黄某某', code: 1 },
        // { name: '张某某', code: 2 },
      ],
      delayList: [
        { name: '是', billId: 1, check: false },
        { name: '否', billId: 0, check: false },
      ],
      creatList: [
        { name: '是', billId: 1, check: false },
        { name: '否', billId: 0, check: false },
      ],
      defeatList: [
        { name: '是', billId: 1, check: false },
        { name: '否', billId: 0, check: false },
      ],
      isflagList: [
        { name: '是', value: 1 },
        { name: '否', value: 0 },
      ],

      delayIndex: null,
      creatIndex: null,
      defeatIndex: null,
      showTransmitFlag: false,
      timeField: '',
      showPickerDate: false,
      currentDate: new Date(),
      list: [],
      // 分页参数
      loading: false,
      finished: false,
      refreshing: false,
      isLoadData: false,

      field: '',
      fieldName: '',
      fixCenterList: [],
      oneBillStatusList: [],
      twoBillStatusList: [],
      // 变更顾问字段
      updateServiceVisible: false,
      updateSelectVisible: false,

      updateServiceData: {
        fixCenterId: '',
        fixCenterName: '',
        followPersonID: '',
        followPersonName: '',
        billIds: '',
      },
      updateDataField: '',
      updateDataChirldenField: '',
      updateDataChirldenFieldName: '',
      updateColumns: [],
      likeWho: '',
      likeWhoField: '',
      followPersonList: [],
      taskResultList: [],
    }
  },
  watch: {
    likeWho: function (nval, oval) {
      if (this.likeWhoField == 'fixCenterId') {
        if (nval) {
          let newArr = this.fixCenterList.filter((item) => {
            return item.name.indexOf(nval) > -1
          })
          console.log(newArr)
          this.columns = newArr
        } else {
          this.columns = this.fixCenterList
        }
      }
      if (this.likeWhoField == 'taskPersonId') {
        if (nval) {
          let newArr = this.followPersonList.filter((item) => {
            return item.name.indexOf(nval) > -1
          })
          console.log(newArr)
          this.columns = newArr
        } else {
          this.columns = this.followPersonList
        }
      }
      if (this.likeWhoField == 'serverPsnId') {
        if (nval) {
          let newArr = this.serviceList.filter((item) => {
            return item.name.indexOf(nval) > -1
          })
          console.log(newArr)
          this.columns = newArr
        } else {
          this.columns = this.serviceList
        }
      }
    },
  },
  created() {
    if (localStorage.getItem('searchParam')) {
      this.requestParams = JSON.parse(localStorage.getItem('searchParam'))
    }
  },
  mounted() {
    this.getTaskType()
    this.getOneBillStatusList()
    this.getTwoBillStatusList()
    this.getTaskResult()
    this.getMainFixCenter()
    this.initData()
    // this.getCustomerTaskWeekCount();
  },
  activated() {
    this.initData()
  },

  methods: {
    // 初始化列表
    initData() {
      this.requestParams.pageNo = 1
      this.loadData()
    },
    // 获取列表
    loadData() {
      if (this.isLoadData) return
      this.isLoadData = true
      this.loading = true
      this.finished = false
      // console.log(this.isLoadData);
      taskApi
        .getCustomerTaskList({ ...this.requestParams })
        .then((res) => {
          if (res.data && res.data.length) {
            res.data.forEach((item) => {
              item.check = false

              item.label = item.label ? item.label.split(';') : []
              if (item && item.label && item.label.length != 0) {
                item.label.length = item.label.length - 1
              }
            })
          }
          if (this.requestParams.pageNo == 1) {
            this.recordList = res.data || []
          } else {
            this.recordList = this.recordList.concat(res.data || [])
          }
          this.requestParams.pageNo += 1

          if (res.data.length < 10) {
            this.finished = true
            this.isLoadData = true
          }
          this.isLoadData = false
          this.loading = false
        })
        .catch((res) => {
          this.loading = false
          this.isLoadData = false
        })
    },
    // 下拉刷新
    onRefresh() {
      // 清空列表数据
      this.recordList = []
      this.finished = false
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.refreshing = false
      this.initData()
    },
    // 获取任务类型
    getTaskType() {
      commonApi.getTaskType({ userId: this.requestParams.userId }).then((res) => {
        this.taskTypeList = this.formatCheckData(res.data)
      })
    },
    // 获取维修中心
    getMainFixCenter() {
      commonApi
        .getMainFixCenter({
          userId: this.requestParams.userId,
          type: 'fixCenter',
        })
        .then((res) => {
          this.fixCenterList = res.data
        })
    },
    // 获取服务顾问
    getEmpPerson() {
      console.log(this.updateServiceData.fixCenterId)
      commonApi
        .getEmpPerson({
          fixCenterId: this.updateSelectVisible ? this.updateServiceData.fixCenterId : this.requestParams.fixCenterId,
          userId: this.requestParams.userId,
          type: 'taskFollow',
        })
        .then((res) => {
          this.serviceList = res.data
        })
    },
    // 获取跟进人员
    getFollowPerson() {
      commonApi
        .getEmpPerson({
          fixCenterId: this.updateSelectVisible ? this.updateServiceData.fixCenterId : this.requestParams.fixCenterId,
          userId: this.requestParams.userId,
          type: 'followPerson',
        })
        .then((res) => {
          this.followPersonList = res.data
        })
    },

    // 获取保险一级状态
    getOneBillStatusList() {
      commonApi.getEnums({ key: 'oneBillStatus', userId: this.requestParams.userId }).then((res) => {
        if (res.data) {
          this.oneBillStatusList = this.formatCheckData(res.data)
          this.oneBillStatusList = this.oneBillStatusList.filter((item) => item.value != 'isNull')
        }
      })
    },
    // 获取保险一级状态
    getTwoBillStatusList() {
      commonApi.getEnums({ key: 'twoBillStatus', userId: this.requestParams.userId }).then((res) => {
        if (res.data) {
          this.twoBillStatusList = this.formatCheckData(res.data)
        }
      })
    },
    // 获取是否到店枚举
    getTaskResult() {
      commonApi.getEnums({ key: 'taskResult', userId: this.requestParams.userId }).then((res) => {
        if (res.data) {
          this.taskResultList = this.formatCheckData(res.data)
        }
      })
    },

    // 格式化多选数据
    formatCheckData(data) {
      data.forEach((item) => {
        item.check = false
      })
      return data
    },

    // 选择下拉
    handleSelect(field, fieldName) {
      if ((field == 'serverPsnId' || field == 'taskPersonId') && !this.requestParams.fixCenterId) {
        Toast('请先选择维修中心')
        return
      }
      this.showSelectPicker = true
      if (field == 'carCoupon') {
        this.columns = [
          { name: '是', value: 1 },
          { name: '否', value: 2 },
        ]
      } else if (field == 'serverPsnId') {
        this.columns = this.serviceList
      } else if (field == 'fixCenterId') {
        this.columns = this.fixCenterList
      } else if (field == 'taskPersonId') {
        this.columns = this.followPersonList
      } else if (field == 'taskResult') {
        this.columns = this.taskResultList
      }
      this.likeWhoField = field

      this.field = field
      this.fieldName = fieldName
    },

    // 筛选是否
    handleCarSelect(index) {
      this.carCouponIndex = index
    },
    // 筛选重置
    handleSelectReset(ref) {
      this.requestParams.taskPersonId = ''
      this.requestParams.isGenRepBook = ''
      if (ref == 'statusRef') {
        this.oneBillStatusList.forEach((item) => {
          item.check = false
        })
        this.twoBillStatusList.forEach((item) => {
          item.check = false
        })
        this.requestParams.oneBillStatus = ''
        this.requestParams.twoBillStatus = ''
      }
      if (ref == 'followRef') {
        this.requestParams.taskStartCreateTime = ''
        this.requestParams.taskEndCreateTime = ''
        this.serviceList = []
      }
      if (ref == 'taskTypeRef') {
        this.taskTypeList.forEach((item) => {
          item.check = false
        })
        this.requestParams.taskTypeId = ''
      }
    },

    // 选择下拉确认
    handleSelectConfirm(value, index) {
      if (this.field == 'taskResult') {
        this.requestParams[this.field] = value.value
        this.requestParams[this.fieldName] = value.name
      } else {
        this.requestParams[this.field] = value.billId
        this.requestParams[this.fieldName] = value.name
      }

      if (this.field == 'fixCenterId') {
        this.getEmpPerson()
        this.getFollowPerson()
        this.requestParams.serverPsnId = ''
        this.requestParams.serverPsnName = ''
      }
      this.likeWho = ''
      this.likeWhoField = ''
      this.showSelectPicker = false
    },

    // 所属服务顾问重置
    handleReset() {
      this.requestParams.fixCenterId = ''
      this.requestParams.outUser = ''
    },

    //时间重置
    handleAccidentReset() {
      this.creatIndex = null
      this.defeatIndex = null
      this.delayIndex = null
      this.requestParams.isExceed = ''
      this.requestParams.isGenRepBook = ''
      this.requestParams.fixCenterId = ''
      this.requestParams.fixCenterName = ''
      this.requestParams.serverPsnId = ''
      this.requestParams.serverPsnName = ''
      this.requestParams.taskPersonId = ''
      this.requestParams.taskPersonName = ''
      this.requestParams.isHuiYuan = ''
      this.requestParams.isFactTask = ''
      this.requestParams.isFollowPerson = ''
      this.requestParams.taskResult = ''
      this.requestParams.taskResultName = ''
      localStorage.setItem('searchParam', '')
    },
    onConfirm(ref) {
      this.$refs[ref].toggle()
      if (ref == 'taskTypeRef') {
        let checkList = []
        this.taskTypeList.forEach((el) => {
          if (el.check) {
            checkList.push(el.billId)
          }
          this.requestParams.taskTypeId = checkList.join(';')
        })
      }
      if (ref == 'statusRef') {
        let checkList = []
        this.oneBillStatusList.forEach((el) => {
          if (el.check) {
            checkList.push(el.value)
          }
          this.requestParams.oneBillStatus = checkList.join(';')
        })
        let checkList2 = []
        this.twoBillStatusList.forEach((el) => {
          if (el.check) {
            checkList2.push(el.value)
          }
          this.requestParams.twoBillStatus = checkList2.join(';')
        })
      }
      if (ref == 'filterRef') {
      }
      this.initData()
    },
    // 时间确认
    onConfirmDate() {
      this.requestParams[this.timeField] = `${this.value1}-${this.value2}-${this.value3}` // 字符串拼接 结果入2020-07-03
      this.onCancelDate()
    },
    onCancelDate() {
      this.showPickerDate = false
    },

    // 日期组件自定义格式
    formatter(type, value) {
      if (type === 'year') {
        this.value1 = value // 可以拿到当前点击的数值
        return `${value}年`
      } else if (type === 'month') {
        this.value2 = value
        return `${value}月`
      }
      this.value3 = value
      return `${value}日`
    },

    // 获取list名称
    getFieldName(list, key, val) {
      if (list && list.length > 0) {
        let obj = list.filter((item) => {
          return item[key] == val
        })
        if (obj.length > 0) {
          return obj[0].name
        }
      }
      return null
    },

    // 详情
    goDetail(data) {
      localStorage.setItem('taskBillId', data.billId)
      this.$router.push({
        path: '/taskCenterDetail',
      })
    },
    // 顶部筛选选择数据
    handleSearchSelect(index, listKey) {
      console.log(listKey)

      this[listKey][index].check = !this[listKey][index].check
      console.log(this[listKey])
    },
    // 重置任务状态
    handleSearchReset() {
      this.taskTypeList.forEach((item) => {
        item.check = false
      })
    },

    // 是否数据选择
    handleIsSelect(index, key, list, field) {
      this[key] = index
      this.requestParams[field] = this[list][index].billId
    },
    // 任务转交展示
    handleShowTransmit() {
      this.showTransmitFlag = true
    },
    // 确认转交
    handleTransmitSubmit() {
      let ids = []
      for (let i = 0; i < this.recordList.length; i++) {
        let item = this.recordList[i]
        if (item.check) {
          ids.push(item.billId)
        }
      }
      if (ids.length == 0) {
        Notify({ type: 'danger', message: '请至少选择一个任务' })
        return
      }
      this.updateServiceData.billIds = ids.join(';')
      this.updateServiceVisible = true
    },
    // 取消
    handleTransmitCancel() {
      this.showTransmitFlag = false
    },
    // 时间筛选
    handleSelectTime(field) {
      this.timeField = field
      this.showPickerDate = true
    },
    // 弹窗下拉
    handleUpdateSelect(data, field, fieldName) {
      this.updateSelectVisible = true
      this.updateDataField = data
      this.updateDataChirldenField = field
      this.updateDataChirldenFieldName = fieldName
      if (field == 'fixCenterId') {
        this.updateColumns = this.fixCenterList
        console.log(this.followPersonList)
      }
      if (field == 'followPersonID') {
        this.updateColumns = this.followPersonList
      }
    },
    // 更新下拉确认
    handleUpdateSelectConfirm(value) {
      this[this.updateDataField][this.updateDataChirldenFieldName] = value.name
      this[this.updateDataField][this.updateDataChirldenField] = value.billId
      if (this.updateDataField == 'updateServiceData') {
        this.getFollowPerson()
      }
      this.updateSelectVisible = false
    },

    // 任务转交
    showUpdateService(data) {
      this.updateServiceVisible = true
    },

    // 任务转交
    updateServiceConfirm() {
      if (!this.updateServiceData.fixCenterId) {
        Notify({ type: 'danger', message: '请选择维修中心' })
        return
      }
      if (!this.updateServiceData.followPersonID) {
        Notify({ type: 'danger', message: '请选择跟进人' })
        return
      }
      taskApi
        .customerTaskFollow({
          ...this.updateServiceData,
        })
        .then((res) => {
          if (res.code == 1) {
            Notify({ type: 'success', message: '更新成功' })
            this.showTransmitFlag = false
            this.onRefresh()
          } else {
            Notify({ type: 'danger', message: res.errorMessage })
          }
        })

      this.updateServiceVisible = false

      this.clearDialogData()
    },
    // 清除弹窗信息
    clearDialogData() {
      this.updateServiceData = {
        fixCenterId: '',
        fixCenterName: '',
        followPersonID: '',
        followPersonName: '',
        billIds: '',
      }
    },
    beforeCloseUpdateTel(action, done) {
      if (action === 'confirm') {
        return done(false)
      } else {
        return done()
      }
    },
    clearSearch() {
      this.requestParams.codeNo = ''
      this.initData()
    },
    onClickLeft() {
      this.handleSearchReset()
      this.$router.go(-1)
    },
    saveSearch() {
      localStorage.setItem('searchParam', JSON.stringify(this.requestParams))
      Toast('保存成功')
    },
    getCustomerTaskWeekCount() {
      taskApi.getCustomerTaskWeekCount({}).then((res) => {
        if (res.code == 1) {
        }
      })
    },
    // 重置任务状态
    handleSearchReset() {
      this.taskTypeList.forEach((item) => {
        item.check = false
      })
      this.oneBillStatusList.forEach((item) => {
        item.check = false
      })
      this.twoBillStatusList.forEach((item) => {
        item.check = false
      })

      this.taskResultList.forEach((item) => {
        item.check = false
      })
      this.requestParams.oneBillStatus = ''
      this.requestParams.twoBillStatus = ''
      this.requestParams.taskStartCreateTime = ''
      this.requestParams.taskEndCreateTime = ''
      this.requestParams.taskTypeId = ''
      this.requestParams.fixCenterId = ''
      this.requestParams.outUser = ''
      this.requestParams.fixCenterId = ''
      this.requestParams.fixCenterName = ''
      this.requestParams.serverPsnId = ''
      this.requestParams.serverPsnName = ''
      this.requestParams.taskPersonId = ''
      this.requestParams.taskPersonName = ''
      this.requestParams.isHuiYuan = ''
      this.requestParams.isFactTask = ''
      this.requestParams.isFollowPerson = ''
      this.requestParams.taskResult = ''
      this.requestParams.taskResultName = ''
      this.serviceList = []
      localStorage.setItem('searchParam', '')
    },
  },
}
</script>
<style>
html,
body {
  font-size: 50px !important;
  background: #fff;
  box-sizing: border-box;
}
</style>
<style lang="less" scoped="">
body {
}
.home {
  background: #f3f3f3;
}
.search_content {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 2;
}
.timebox {
  /deep/.van-cell::after {
    border: none;
  }
  .time_item {
    /deep/.van-field__control--right {
      border: 1px solid #d1d1d1;
      padding: 0.1rem 0;
      text-align: center;
      border-radius: 3px;
    }
  }
}
.searchbox {
  padding: 0.3rem;
  .time_icon {
    font-size: 24px;
    color: #999;
  }
  .title {
    font-size: 0.3rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 0.2rem;
    padding-top: 0.2rem;
  }
  .insureList {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    .insure_item {
      text-align: center;
      padding: 0.15rem 0rem;
      width: 30%;
      box-sizing: border-box;
      font-size: 0.28rem;
      border-radius: 3px;
      color: #666;
      margin-bottom: 0.2rem;
      margin-right: 5%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.5);
      &:nth-child(3n) {
        margin-right: 0;
      }
      &.active {
        box-shadow: 0px 0px 3px 0px #f65e07;
        color: #f65e07;
      }
    }
  }
  .insureBtn {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.4rem;
    .resetBtn {
      padding: 0 0.4rem;
      margin-right: 0.2rem;
    }
    .confirmBtn {
      padding: 0 0.4rem;
      margin-right: 0.2rem;
    }
    .saveBtn {
      padding: 0 0.4rem;
      margin-right: 0.2rem;
    }
  }
}

.orderList {
  padding-top: 3rem;
  margin: 0.2rem;
  overflow: hidden;
  .orderbox {
    width: 100%;
  }
  // padding-bottom: 1.5rem;
  .taskCheck {
    margin-right: 0.1rem;
  }
  .orderItem {
    padding: 0.3rem 0.2rem;
    background: #fff;
    border-radius: 10px;
    width: 100%;
    margin-bottom: 0.3rem;
    .orderItem_box {
      margin-bottom: 0.3rem;
      padding-bottom: 0.2rem;
      border-bottom: 1px solid #f6f6f6;
      position: relative;
      .vinNobox {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 0.2rem;
        width: 100%;
      }
      .vinNo {
        font-size: 0.28rem;
        color: #333;
      }
    }
    .orderItem_header {
      // display: flex;
      justify-content: space-between;
      align-items: center;

      .orderItem_lt {
        .carNo {
          font-size: 0.3rem;
          color: #333;
          margin-right: 0.2rem;
          font-weight: bold;
        }

        .carStatus {
          background: #35bc04;
          color: #fff;
          border-radius: 4px;
          padding: 5px;
          font-size: 0.24rem;
          text-align: center;
          width: 1rem;
          margin-top: 0.1rem;
          margin-right: 5px;
        }
      }
      .orderItem_rt {
        display: flex;
        align-items: center;
        align-self: center;
        justify-content: flex-start;
        color: #666;
        font-size: 0.24rem;

        .txt {
          font-size: 0.28rem;
          color: #161616;
        }
        .icon-tel {
          color: #fff;
          background: #35bc04;
          font-size: 0.32rem;
          padding: 0.1rem;
          border-radius: 50%;
          margin-right: 0.2rem;
        }
        .icon-wx {
          color: #409eff;
          font-size: 0.65rem;
        }
      }
    }
    .orderItem_content {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      align-items: center;
      border-bottom: 1px solid #eeeeee;
      margin-bottom: 10px;
      .orderItem_data {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        width: 50%;
        margin-bottom: 0.2rem;
        font-size: 0.28rem;
        box-sizing: content-box;
        color: #333;
        .order_label {
          font-size: 0.28rem;
          color: #333;
          // width: 1.8rem;
          margin-right: 10px;
        }
        .txt {
          font-size: 0.28rem;
          color: #666;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        &.time {
          width: 100%;
        }
      }
    }
    .orderItem_label {
      .label_item {
        color: #fff;
        // border: 1px solid #35bc04;
        background: #272da7;
        border-radius: 4px;
        margin-right: 0.1rem;
        min-width: 0.4rem;
        padding: 5px 10px;
        text-align: center;
        font-size: 0.2rem;
        float: left;
        margin-bottom: 0.1rem;
        &:last-child {
          margin-right: 0;
        }
      }
    }
    .orderItem_file {
      background: #ebebeb;
      color: #333;
      border-radius: 5px;
      padding: 0.2rem 0;
      text-align: center;
      width: 100%;
      font-size: 0.28rem;
      display: flex;
      align-items: center;
      justify-content: center;
      .file_item {
        width: 33.33%;
        border-right: 1px solid #ccc;
        .icon-tel {
          font-size: 0.34rem;
          color: #35bc04;
          margin-right: 0.1rem;
        }
        .icon-mileage {
          font-size: 0.4rem;
          color: #409eff;
          margin-right: 0.1rem;
          position: relative;
          top: 0.04rem;
        }
        .icon-gw {
          font-size: 0.4rem;
          color: #409eff;
          margin-right: 0.1rem;
          position: relative;
          top: 0.04rem;
        }
        &:last-child {
          border: none;
        }
      }
    }
  }
}
.addBtn {
  position: fixed;
  bottom: 0.8rem;
  width: 100%;
  z-index: 1;
  .footerBtn {
    width: 2.8rem;
    margin: auto;
    text-align: center;
    font-size: 0.28rem;
    padding: 0.25rem 0rem;
    border-radius: 50px;
  }
  .orderItem_filebox {
    margin: auto;
    background: #409eff;
    color: #fff;
  }
  .comfirmBtn {
    background: #409eff;
    color: #fff;
  }
  .cancelBtn {
    border: 1px solid #ccc;
    color: #999;
    background: #fff;
  }
}
.noContent {
  margin-top: 2rem;
}
</style>
